package com.example.sjc715.main.ui.live

import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.example.commonlibrary.mvi.BaseFragment
import com.example.commonlibrary.util.CommonAdapter
import com.example.net_library.entity.RecommonEntity
import com.example.net_library.entity.SimpleVideoEntity
import com.example.sjc715.BR
import com.example.sjc715.R
import com.example.sjc715.databinding.FragmentLiveBinding
import com.example.sjc715.main.ui.home.HomeState


class LiveFragment : BaseFragment<FragmentLiveBinding,LiveViewModel>() {
    val hAdapter by lazy {
        CommonAdapter<SimpleVideoEntity>({R.layout.cate to BR.live})
    }
    val vAdapter by lazy {
        CommonAdapter<RecommonEntity>({ R.layout.live to BR.video })
    }
    override fun initView() {
        binding.rec1.adapter = hAdapter
        binding.rec2.adapter = vAdapter

        viewModel.intent.trySend(LiveIntent.LoadRecommend(1,10))
        viewModel.intent.trySend(LiveIntent.loadVideo("94349547025",1,10))
    }

    override fun initData() {
        viewModel.state.observe(this){
            when(it){
                is LiveState.RecommendSuccess->{
                    vAdapter+=it.recommend.data
                }
               is LiveState.VideoSuccess->{
                   hAdapter+=it.video.data
               }
            }
        }
    }

}